package com.example.librarysysee.service;


import com.example.librarysysee.enums.BookStatusEnum;
import com.example.librarysysee.mapper.BookInfoMapper;
import com.example.librarysysee.model.BookInfo;
import com.example.librarysysee.model.PageRequest;
import com.example.librarysysee.model.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.print.Book;
import java.util.List;

@Service
public class BookService {
    @Autowired
    BookInfoMapper bookInfoMapper;
    public Integer addBook(BookInfo bookInfo) {
        return bookInfoMapper.insertBook(bookInfo);
    }

    public PageResult<BookInfo> getListByPage(PageRequest pageRequest) {
        Integer cnt = bookInfoMapper.count();
        List<BookInfo> bookInfos = bookInfoMapper.queryListByPage(pageRequest);
        for(BookInfo x : bookInfos){
            x.setStateCN(BookStatusEnum.getDescByCode(x.getStatus()).getDesc());
        }
        return new PageResult<>(bookInfos,cnt,pageRequest);
    }

    public BookInfo queryBookById(Integer id) {
        return bookInfoMapper.queryBookById(id);
    }

    public Integer updateBook(BookInfo bookInfo) {
        return bookInfoMapper.updateBook(bookInfo);
    }

    public Integer batchDelete(List<Integer> ids) {
        return bookInfoMapper.batchDeleteBook(ids);
    }
}
